home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / The GIMP / gimp-2.6.8-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / palette-to-gradient.py < prev    next >
Encoding:
Python Source  |  2009-12-15  |  3.3 KB  |  87 lines

  1. #!/usr/bin/env python
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. from gimpfu import *
  18.  
  19. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  20.  
  21. def make_gradient(palette, num_segments, num_colors):
  22.     gradient = pdb.gimp_gradient_new(palette)
  23.     pdb.gimp_gradient_segment_range_split_uniform(gradient, 0, -1, num_segments)
  24.  
  25.     for color_number in range(0,num_segments):
  26.         if (color_number == num_colors-1):color_number_next = 0
  27.         else: color_number_next = color_number + 1
  28.         color_left = pdb.gimp_palette_entry_get_color(palette,
  29.                                                       color_number)
  30.         color_right = pdb.gimp_palette_entry_get_color(palette,
  31.                                                        color_number_next)
  32.         pdb.gimp_gradient_segment_set_left_color(gradient,
  33.                                                  color_number, color_left,
  34.                                                  100.0)
  35.         pdb.gimp_gradient_segment_set_right_color(gradient,
  36.                                                   color_number, color_right,
  37.                                                   100.0)
  38.     pdb.gimp_context_set_gradient(gradient)
  39.     return gradient
  40.  
  41.  
  42. def palette_to_gradient_repeating(palette):
  43.     num_colors = pdb.gimp_palette_get_info(palette)
  44.     num_segments = num_colors
  45.     return make_gradient(palette, num_segments, num_colors)
  46.  
  47.  
  48. register(
  49.     "python-fu-palette-to-gradient-repeating",
  50.     N_("Create a repeating gradient using colors from the palette"),
  51.     "Create a new repeating gradient using colors from the palette.",
  52.     "Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
  53.     "Carol Spears",
  54.     "2006",
  55.     N_("Palette to _Repeating Gradient"),
  56.     "",
  57.     [(PF_PALETTE,  "palette", _("Palette"), "")],
  58.     [(PF_GRADIENT, "new-gradient", "Result")],
  59.     palette_to_gradient_repeating,
  60.     menu="<Palettes>",
  61.     domain=("gimp20-python", gimp.locale_directory)
  62.     )
  63.  
  64.  
  65. def palette_to_gradient(palette):
  66.     num_colors = pdb.gimp_palette_get_info(palette)
  67.     num_segments = num_colors - 1
  68.     return make_gradient(palette, num_segments, num_colors)
  69.  
  70. register(
  71.     "python-fu-palette-to-gradient",
  72.     N_("Create a gradient using colors from the palette"),
  73.     "Create a new gradient using colors from the palette.",
  74.     "Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
  75.     "Carol Spears",
  76.     "2006",
  77.     N_("Palette to _Gradient"),
  78.     "",
  79.     [(PF_PALETTE,  "palette", _("Palette"), "")],
  80.     [(PF_GRADIENT, "new-gradient", "Result")],
  81.     palette_to_gradient,
  82.     menu="<Palettes>",
  83.     domain=("gimp20-python", gimp.locale_directory)
  84.     )
  85.  
  86. main ()
  87.